package com.example.demo.common;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-08-30
 * Time:15:08
 */

import com.example.demo.entity.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 当前登录用户相关的操作
 */
public class UserSessionUtils {
    /**
     * 得到当前的登录用户
     */
    public static Userinfo getSessionUser(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(AppVariable.USER_SESSION_KEY) != null){
            //当前用户已登录
            return (Userinfo) session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        return null;
    }

    /**
     * 得到当前验证码
     * @param request
     * @return
     */
    public static String getImgCode(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(AppVariable.LOGIN_CHECK_CODE) != null) {
            return (String) session.getAttribute(AppVariable.LOGIN_CHECK_CODE);
        }
        return null;
    }

}
